<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="处理名称" prop="animalHandingName">
        <el-input
          v-model="queryParams.animalHandingName"
          placeholder="请输入处理名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数量" prop="animalHandingNum">
        <el-input
          v-model="queryParams.animalHandingNum"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="动物ID" prop="animalId">
        <el-input
          v-model="queryParams.animalId"
          placeholder="请输入动物ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="动物名称" prop="animalHandingBy2">
        <el-input
          v-model="queryParams.animalHandingBy2"
          placeholder="请输入动物名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="申请日期" prop="animalHandingCreatTime">
        <el-date-picker clearable
          v-model="queryParams.animalHandingCreatTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择申请日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="处理状态" prop="animalHandingBy3">
        <el-select v-model="queryParams.animalHandingBy3" placeholder="请选择" @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <!-- <el-input
          v-model="queryParams.animalHandingBy3"
          placeholder="请输入处理状态"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
      </el-form-item>
      <el-form-item label="处理日期" prop="animalHandingHandingTime">
        <el-date-picker clearable
          v-model="queryParams.animalHandingHandingTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择处理日期">
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="申请人ID" prop="staffId">
        <el-input
          v-model="queryParams.staffId"
          placeholder="请输入申请人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="处理人ID" prop="staffHandingId">
        <el-input
          v-model="queryParams.staffHandingId"
          placeholder="请输入处理人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="处理人姓名" prop="animalHandingDesc">
        <el-input
          v-model="queryParams.animalHandingDesc"
          placeholder="请输入处理人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['handing:animalHanding:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['handing:animalHanding:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['handing:animalHanding:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['handing:animalHanding:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="animalHandingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="处理ID" align="center" prop="animalHandingId" />
      <el-table-column label="处理名称" align="center" prop="animalHandingName" />
      <el-table-column label="数量" align="center" prop="animalHandingNum" />
      <el-table-column label="动物ID" align="center" prop="animalId" v-if="false"/>
      <el-table-column label="动物名称" align="center" prop="animalHandingBy2" /> 
      <el-table-column label="处理状态" align="center" prop="animalHandingBy3" /> 
      <el-table-column label="申请日期" align="center" prop="animalHandingCreatTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.animalHandingCreatTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理日期" align="center" prop="animalHandingHandingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.animalHandingHandingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="申请人ID" align="center" prop="staffId" /> -->
      <!-- <el-table-column label="处理人ID" align="center" prop="staffHandingId" /> -->
      <el-table-column label="处理人姓名" align="center" prop="animalHandingDesc" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['handing:animalHanding:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['handing:animalHanding:remove']"
          >删除</el-button> -->
          <p v-if="scope.row.animalHandingBy3=='已处理'">
            <el-button disabled
              size="mini"
              type="text"
              icon="el-icon-check"
              @click="yichuli(scope.row)"
            >已处理</el-button>
          </p>
          <p v-if="scope.row.animalHandingBy3=='处理中'">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-check"
              @click="yichuli(scope.row)"
            >已处理</el-button>
          </p>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改动物处理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="处理名称" prop="animalHandingName">
          <el-input v-model="form.animalHandingName" placeholder="请输入处理名称" />
        </el-form-item>
        <el-form-item label="数量" prop="animalHandingNum">
          <el-input v-model="form.animalHandingNum" placeholder="请输入数量" />
        </el-form-item>
        <!-- <el-form-item label="动物ID" prop="animalId">
          <el-input v-model="form.animalId" placeholder="请输入动物ID" />
        </el-form-item> -->
        <el-form-item label="动物名称" prop="animalHandingBy1">
          <el-input v-model="form.animalHandingBy1" placeholder="请输入动物名称" />
        </el-form-item>
        <el-form-item label="申请日期" prop="animalHandingCreatTime">
          <el-date-picker clearable
            v-model="form.animalHandingCreatTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择申请日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理日期" prop="animalHandingHandingTime">
          <el-date-picker clearable
            v-model="form.animalHandingHandingTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择处理日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="申请人ID" prop="staffId">
          <el-input v-model="form.staffId" placeholder="请输入申请人ID" />
        </el-form-item>
        <el-form-item label="处理人ID" prop="staffHandingId">
          <el-input v-model="form.staffHandingId" placeholder="请输入处理人ID" />
        </el-form-item>
        <el-form-item label="处理人姓名" prop="animalHandingDesc">
          <el-input v-model="form.animalHandingDesc" placeholder="请输入处理人姓名" />
        </el-form-item>
        <!-- <el-form-item label="备用列" prop="animalHandingBy2">
          <el-input v-model="form.animalHandingBy2" placeholder="请输入备用列" />
        </el-form-item>
        <el-form-item label="备用列" prop="animalHandingBy3">
          <el-input v-model="form.animalHandingBy3" placeholder="请输入备用列" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAnimalHanding, getAnimalHanding, delAnimalHanding, addAnimalHanding, updateAnimalHanding, chuli } from "@/api/handing/animalHanding";

export default {
  name: "AnimalHanding",
  data() {
    return {
      options: [{
          value: '处理中',
          label: '处理中'
        }, {
          value: '已处理',
          label: '已处理'
        }],
        value: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 动物处理表格数据
      animalHandingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        animalHandingName: null,
        animalHandingNum: null,
        animalId: null,
        animalHandingCreatTime: null,
        animalHandingHandingTime: null,
        staffId: null,
        staffHandingId: null,
        animalHandingDesc: null,
        animalHandingBy1: null,
        animalHandingBy2: null,
        animalHandingBy3: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询动物处理列表 */
    getList() {
      this.loading = true;
      listAnimalHanding(this.queryParams).then(response => {
        this.animalHandingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        animalHandingId: null,
        animalHandingName: null,
        animalHandingNum: null,
        animalId: null,
        animalHandingCreatTime: null,
        animalHandingHandingTime: null,
        staffId: null,
        staffHandingId: null,
        animalHandingDesc: null,
        animalHandingBy1: null,
        animalHandingBy2: null,
        animalHandingBy3: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.animalHandingId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加动物处理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const animalHandingId = row.animalHandingId || this.ids
      getAnimalHanding(animalHandingId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改动物处理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.animalHandingId != null) {
            updateAnimalHanding(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAnimalHanding(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const animalHandingIds = row.animalHandingId || this.ids;
      this.$modal.confirm('是否确认删除动物处理编号为"' + animalHandingIds + '"的数据项？').then(function() {
        return delAnimalHanding(animalHandingIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('handing/animalHanding/export', {
        ...this.queryParams
      }, `animalHanding_${new Date().getTime()}.xlsx`)
    },
    yichuli(row){
      const animalHandingIds = row.animalHandingId || this.ids;
      this.$modal.confirm('是否确认处理"' + animalHandingIds + '？').then(function() {
        return chuli(animalHandingIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("已处理");
      }).catch(() => {});
    }
  }
};
</script>
